package com.hongxin.nw.netty.down;

import com.alibaba.fastjson.JSONObject;
import com.hongxin.nw.netty.model.Transfer;
import com.hongxin.nw.netty.utils.JSONUtils;
import com.hongxin.nw.netty.utils.RequestCtx;
import com.hongxin.nw.netty.values.StaticValue;

/**
 * @remark 确认
 * @author: GuoXiaolin
 * @date 2019/6/24 10:23
 * @Version 1.0
 * @Descibe
 */
public class ChannelRequest {
    private IChannelRequest iChannelRequest;

    public ChannelRequest(IChannelRequest iChannelRequest){
        this.iChannelRequest = iChannelRequest;
    }

    public JSONObject execute(Transfer transfer) throws Exception{
        String str = this.iChannelRequest.doPacking(transfer);
        JSONObject jsonObject = RequestCtx.sendCmdByAutoCid(str, transfer.getCode());
        if (jsonObject.getIntValue(JSONUtils.JSON_CODE) == 0){
            return JSONUtils.getRoot(0, StaticValue.VAL_22, jsonObject.getString(JSONUtils.JSON_DATA));
        }
        return jsonObject;
    }
}
